package com.tledu.ssm.service.impl;

import com.tledu.ssm.core.exception.LoginException;
import com.tledu.ssm.dao.UserDao;
import com.tledu.ssm.model.User;
import com.tledu.ssm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {
    @Autowired
    private UserDao userDao;

    @Override
    public User selectById(Integer id) {
        return userDao.selectById(id);
    }

    @Override
    public User login(String username, String password) throws LoginException {
        User user = userDao.selectByUserName(username);
        if (user == null) {
            throw new LoginException("用户不存在");
        }
        if (!user.getPassword().equals(password)) {
            throw new LoginException("密码错误");
        }
        return user;
    }

    @Override
    public List<User> list() {
        return userDao.list();
    }
}
